<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>控制面板</title>
    <style>
        /* 页面背景和字体设置 */
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f9;
            margin: 0;
            padding: 0;
            color: #333;
            background-image: url('./beijing.png');
            background-size: cover;  /* 让图片充满整个页面 */
            background-position: center;  /* 图片居中 */
        }

        /* 页面容器 */
        .container {
            width: 90%;
            margin: 0 auto;
            padding-top: 50px;
            opacity: 0.9;
        }

        /* 页面标题 */
        h1 {
            text-align: center;
            color: #5e5e5e;
        }

        /* 导航链接样式 */
        nav {
            text-align: center;
            margin-bottom: 30px;
        }

        nav a {
            margin: 0 15px;
            text-decoration: none;
            color: #007bff;
            font-size: 18px;
            font-weight: bold;
        }

        nav a:hover {
            color: #0056b3;
        }

        /* 表单容器 */
        form {
            background-color: #ffffff;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
            display: grid;
            grid-template-columns: repeat(4, 1fr); /* 默认每行4个模块 */
            gap: 20px; /* 设置模块之间的间距 */
        }

        /* 每个数据项模块样式 */
        .data-module {
            background-color: #ffffff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
        }

        /* 模块标题 */
        .data-module label {
            font-weight: bold;
            margin-bottom: 10px;
        }

        /* 输入框样式 */
        form input[type="text"] {
            width: 100%;
            padding: 10px;
            margin: 10px 0;
            border: 1px solid #ccc;
            border-radius: 4px;
            font-size: 16px;
        }

        /* 响应式布局：小屏幕下每行显示1个或2个模块 */
        @media screen and (max-width: 1200px) {
            form {
                grid-template-columns: repeat(3, 1fr); /* 每行3个模块 */
            }
        }

        @media screen and (max-width: 768px) {
            form {
                grid-template-columns: repeat(2, 1fr); /* 每行2个模块 */
            }
        }

        @media screen and (max-width: 480px) {
            form {
                grid-template-columns: 1fr; /* 每行1个模块 */
            }
        }

        /* 视频容器样式 */
        #video-container {
            text-align: center;
            margin: 20px;
            width: 100%;
        }

        #video {
            width: 80%;
            max-width: 600px;
        }

        /* 提交按钮样式 */
        .submit-btn {
            background-color: #007bff;
            color: white;
            border: none;
            padding: 12px 25px;
            border-radius: 5px;
            font-size: 18px;
            cursor: pointer;
            margin-top: 20px;
            display: block;
            width: 100%;
            transition: background-color 0.3s ease;
        }

        .submit-btn:hover {
            background-color: #0056b3;
        }
    </style>
    <script type="text/javascript">
        setInterval(function() {
                init();
                }, 1000);
        function init() {
            refresh();
        }

        function refresh() {
            var xhr = new XMLHttpRequest();
            var url = ""; // 请求的URL

            xhr.open("POST", url, true);

            var post_req = {
                "type": 1,
                "limit": "all"
            };

            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    var response = xhr.responseText;
                    var info = JSON.parse(response);
                    console.log(info);
                    for (var i = 0; i < info.data.length; i++) {
                        if (info.data[i].key == 101) {
                            document.getElementById('temperature_modbus').value = info.data[i].val;
                        } else if (info.data[i].key == 102) {
                            document.getElementById('humidity').value = info.data[i].val;
                        } else if (info.data[i].key == 104) {
                            document.getElementById('air-temp').value = info.data[i].val;
                        } else if (info.data[i].key == 106) {
                            document.getElementById('light-data').value = info.data[i].val;
                        } else if (info.data[i].key == 108) {
                            document.getElementById('oxygen-data').value = info.data[i].val;
                        } else if (info.data[i].key == 303) {
                            document.getElementById('temperature').value = info.data[i].val;
                        } else if (info.data[i].key == 304) {
                            document.getElementById('bat').value = info.data[i].val;
                        } else if (info.data[i].key == 311) {
                            document.getElementById('heart').value = info.data[i].val;
                        }
                    }
                }
            };

            xhr.send(JSON.stringify(post_req));
        }
    </script>
</head>
<body onload="init()">
    <div class="container">
        <h1>基于边缘网关的智能医疗监护系统</h1>
        <nav>
            <a href="temp_stm32.html">控制页面</a>
            <a href="temp_modbus.html">数据显示页面</a>
            <a href="1.html">实时环境监控</a>
        </nav>
        <form>
            <!-- 每个数据项模块 -->
            <div class="data-module">
                <label for="temperature">人体温度</label>
                <input type="text" id="temperature" value="" />
            </div>

            <div class="data-module">
                <label for="bat">电池电量</label>
                <input type="text" id="bat" value="" />
            </div>

            <div class="data-module">
                <label for="heart">心率</label>
                <input type="text" id="heart" value="" />
            </div>

            <div class="data-module">
                <label for="temperature_modbus">环境温度</label>
                <input type="text" id="temperature_modbus" value="" />
            </div>

            <div class="data-module">
                <label for="humidity">空气湿度</label>
                <input type="text" id="humidity" value="" />
            </div>

            <div class="data-module">
                <label for="air-temp">温度阈值</label>
                <input type="text" id="air-temp" value="" />
            </div>

            <div class="data-module">
                <label for="light-data">环境亮度</label>
                <input type="text" id="light-data" value="" />
            </div>

            <div class="data-module">
                <label for="oxygen-data">血氧采集</label>
                <input type="text" id="oxygen-data" value="" />
            </div>
        </form>
    </div>
</body>
</html>
